設置 Docker Swarm 環境
docker swarm init
docker-compose.yml
version: '3.8'
services:
web:
image: your-flask-app-image
deploy:
replicas: 3
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
ports:
- "5000:5000"
networks:
- webnet
redis:
image: redis:alpine
networks:
- webnet
networks:
webnet:
部署應用:
docker stack deploy -c docker-compose.yml your_stack_name
檢查服務狀態:
docker service ls
檢查應用狀態:
docker stack ps your_stack_name
擴展或縮減服務:
docker service scale your_stack_name_web=5